﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using public_dbOpt;

namespace prjEMR22_154
{
    public partial class login : Form
    {
        dbOPT dataOpt = new dbOPT();
        public static string strUType = "管理员";//跨窗体公共变量--用户类型

        public login()
        {
            InitializeComponent();
        }

        private void login_button_Click(object sender, EventArgs e)
        {
            if (id.Text != "" && psw.Text != "")
            {
                login_check();
            }
            else
            {
                MessageBox.Show("输入有空项，请重新输入");
            }
        }

        public void login_check()
        {
            if (radioButtonUser.Checked == true)
            {
                string sql = String.Format("select * from t_user where UName ='{0}' and  UPassword ='{1}'",id.Text,psw.Text);
                DataSet ds = new DataSet();//创建数据集
                ds = dataOpt.GetTable(sql);

                if (ds != null && ds.Tables[0].Rows.Count != 0)
                {
                    string UType = ds.Tables[0].Rows[0]["UType"].ToString();
                    if (UType != "普通用户")
                    {
                        MessageBox.Show("登陆失败。");
                    }
                    else
                    {
                        MessageBox.Show("登陆成功。");
                        strUType = "普通用户";
                        this.Hide();
                        Try a = new Try();
                        a.ShowDialog();
                    }
                }
                else
                {
                    // 处理没有数据或查询失败的情况  
                    MessageBox.Show("登陆失败。");
                }
                //MessageBox.Show(sql);
            }
            if (radioButtonAdmi.Checked == true)
            {
                string sql = String.Format("select * from t_user where UName ='{0}' and  UPassword ='{1}'", id.Text, psw.Text);
                DataSet ds = new DataSet();//创建数据集
                ds = dataOpt.GetTable(sql);

                if (ds != null && ds.Tables[0].Rows.Count != 0)
                {
                    string UType = ds.Tables[0].Rows[0]["UType"].ToString();
                    if (UType != "管理员")
                    {
                        MessageBox.Show("登陆失败。");
                    }
                    else
                    {
                        MessageBox.Show("登陆成功。");
                        strUType = "管理员";
                        this.Hide();
                        Try a = new Try();
                        a.ShowDialog();
                    }
                }
                else
                {
                    // 处理没有数据或查询失败的情况  
                    MessageBox.Show("登陆失败。");
                }
            }
        }

        private void cencel_button_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void new_user_Click(object sender, EventArgs e)
        {
            //this.Hide();
            login_NewUser a = new login_NewUser();
            a.ShowDialog();
        }

        private void login_Load(object sender, EventArgs e)
        {
            psw.PasswordChar = '*';   //显示*
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                psw.PasswordChar = '\0';   //显示输入
            }
            else
            {
                psw.PasswordChar = '*';   //显示*
            }
        }

        private void radioButtonUser_CheckedChanged(object sender, EventArgs e)
        {

        }



    }
}
